fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

path

io.path

path:orderable,hashable is[Private constructor][src]
a feature denoting a path/file in the filesystem

instantiate via io.path.of, e.g.


or
io.path.of ["some", "path"] true
Precondition
pre debug: !names.contains "."
    # allow ".." only at start in relative paths
    safety: is_absolute ? !names.contains ".." : !(names.drop_while ="..").contains ".."

Fields

names array String[src]
is_absolute bool[src]

Functions

as_absolute => outcome io.path[src]
relative paths are resolved against the current working
directory (`os.cwd`); absolute paths are returned unchanged
as_platform_string => String[src]
Platform dependent String representation of this path

Relative paths start with "./" to avoid problems on Windows

e.g. "/folder/file" or "./relative_folder/file"
as_string => String[Redefinition of  Any.as_string][src]
String representation of this path

e.g. "/folder/file" or "relative_folder/file"

redefines:

base_name => String[src]
Full file name or name of the last directory
contains(other io.path) => bool[src]
does this path contain other
dynamic_apply(R:Any,F:Typed_Function R,f F) => R[Inherited from  Any][src]
dynamic_apply -- apply `f.call` to `Any.this`'s dynamic type and value

This can be used to perform operation on values depending on their dynamic
type.

Here is an example that takes a `Sequence Any` that may contain boxed values
of types `i32` and `f64`. We can now write a feature `get_f64` that extracts
these values converted to `f64` and build a function `sum` that sums them up
as follows:


dynamic_type => Type[Inherited from  Any][src]
Get the dynamic type of this instance. For value instances `x`, this is
equal to `type_of x`, but for `x` with a `ref` type `x.dynamic_type` gives
the actual runtime type, while `type_of x` results in the static
compile-time type.

There is no dynamic type of a type instance since this would result in an
endless hierarchy of types. So for Type values, dynamic_type is redefined
to just return Type.type.
ends_with(other io.path) => bool[src]
does this path end with other
is_current => bool[src]
is this a relative path representing "current directory"
is_parent => bool[src]
is this a relative path representing "parent directory"
is_relative => bool[src]
is this a relative path
is_root => bool[src]
is this the root
is_single_segment => bool[src]
is this a path with just one segment, i.e. not containing a path separator when normalized
parent => option io.path[src]
get the parent of this path

if folder is root folder or .
nil is returned
parent(n i64) => option io.path[src]
go up n levels, i.e. call parent n times
prefix $ => String[Inherited from  Any][src]
convenience prefix operator to create a string from a value.

This permits usage of `$` as a prefix operator in a similar way both
inside and outside of constant strings: $x and "$x" will produce the
same string.
relativize(p io.path) => io.path[src]
relativize path `p` based on this path.

e.g. "/tmp/folder".relativize "/tmp/folder/file" will return "file"
resolve(o choice io.path String) => io.path[src]
resolve o in this path

e.g.


effectively returns


resolving an absolute path returns that path unmodified
segments_count => i64[src]
the number of segments in this path
starts_with(p io.path) => bool[src]
checks if this path starts with path `p`

both this and path p must either be absolute or relative
for this to return true.

e.g. (io.path.of "/tmp/file").starts_with (io.path.of "/tmp") = true
stem => String[src]
consider this to represent a file
and return just name of the file
without its extension and path.
subpath(from i64) => io.path[src]
get subpath starting from (inclusive)

e.g.
io.path.of "/tmp/folder/file" .subpath 1 = io.path.of "folder/file"
subpath(from i64,to i64) => io.path[src]
get subpath from (inclusive) to (exclusive)

e.g.
io.path.of "/tmp/folder/file" .subpath 0 2 = io.path.of "/tmp/folder"
suffix => String[src]
consider this to represent a file
and return the suffix of the file_name

Type Features

type.as_string => String[Inherited from  Type][src]
string representation of this type to be used for debugging.

result has the form "<name>", but this might change in the future

redefines:

type.current_dir => io.path[src]
the current directory path "."
type.dynamic_type => Type[Inherited from  Type][src]
There is no dynamic type of a type instance since this would result in an
endless hierarchy of types, so dynamic_type is redefined to just return
Type.type here.

Note: Typechecking is undecidable when 'type' is a type, Mark B. Reinhold, 1989
see: https://dspace.mit.edu/bitstream/handle/1721.1/149366/MIT-LCS-TR-458.pdf?sequence=6

redefines:

type.equality(a property.orderable.this,b property.orderable.this) => bool[Inherited from  orderable][src]
equality implements the default equality relation for values of this type.

This relation must be

- reflexive (equality a a),
- symmetric (equality a b = equality b a), and
- transitive ((equality a b && equality b c) : equality a c).

result is true iff 'a' is considered to represent the same abstract value
as 'b'.
type.hash_code(a io.path) => u64[Redefinition of  property.hashable.type.hash_code][src]
create hash code for this instance

This should satisfy the following condition:

(T.equality a b) : (T.hash_code a = T.hash_code b)
type.infix :(T:Any) => bool[Inherited from  Type][src]
Is this type assignable to a type parameter with constraint `T`?

The result of this is a compile-time constant that can be used to specialize
code for a particular type.


it is most useful in conjunction with preconditions or `if` statements as in


or

type.lteq(a io.path,b io.path) => bool[Redefinition of  property.partially_orderable.type.lteq][src]
define order for paths
type.name => String[Inherited from  Type][src]
name of this type, including type parameters, e.g. 'option (list i32)'.
type.of(str String) => io.path[src]
instantiates a path via a given String
if paths starts with / it is considered to be
absolute rather than relative.
type.of(seq Sequence String,is_absolute bool) => io.path[src]
instantiates a path

e.g.

type.parent_dir => io.path[src]
the parent directory path ".."
type.prefix $ => String[Inherited from  Type][src]
convenience prefix operator to create a string from a value.

This permits usage of `$` as a prefix operator in a similar way both
inside and outside of constant strings: $x and "$x" will produce the
same string.

NYI: Redefinition allows the type feature to be distinguished from its normal counterpart, see #3913

redefines:

type.root => io.path[src]
the root path "/"
type.separator => codepoint[src]
the path separator that is used
on the current platform
type.type_value => Type[Inherited from  Any][src]
Get a type as a value.

This is a feature with the effect equivalent to Fuzion's `expr.type` call tail.
It is recommended to use `expr.type` and not `expr.type_value`.

`type_value` is here to show how this can be implemented and to illustrate the
difference to `dynamic_type`.

Applicable universe features

These are features in universe, that have an argument with a type constraint that matches this features type and can therefore be used with it.
equals(T:property.equatable,a T,b T) => bool[src]
equals -- feature that compares two values using the equality relation
defined in their type
hash(T:property.hashable,a T) => u64[src]
hash of a value
infix !=(T:property.equatable,a T,b T) => bool[src]
infix = -- infix operation as shorthand for 'equals'
infix <(T:property.orderable,a T,b T) => bool[src]
does this come strictly before other?
infix <=(T:property.partially_orderable,a T,b T) => bool[src]
infix <= -- infix operation as shorthand for 'lteq'
infix <>(T:property.orderable,a T,b T) => order[src]
three-way comparison between this and other.

result is < 0 if this < other
result is > 0 if this > other
result is = 0 if this = other
infix =(T:property.equatable,a T,b T) => bool[src]
infix = -- infix operation as shorthand for 'equals'
infix >(T:property.orderable,a T,b T) => bool[src]
does this come strictly after other?
infix >=(T:property.orderable,a T,b T) => bool[src]
does this come after other?
infix ∈(T:property.equatable,a T,s container.Set T) => bool[src]
is `a` contained in `Set` `s`?

This should usually be called using type inference as in

infix ∉(T:property.equatable,a T,s container.Set T) => bool[src]
is `a` not contained in `Set` `s`?

This should usually be called using type inference as in

infix ≤(T:property.partially_orderable,a T,b T) => bool[src]
infix ≤ -- infix operation as shorthand for 'lteq'
infix ≥(T:property.orderable,a T,b T) => bool[src]
does this come after other?
infix ⋄(T:property.orderable,a T,b T) => order[src]
three-way comparison between this and other.

result is < 0 if this < other
result is > 0 if this > other
result is = 0 if this = other
lteq(T:property.partially_orderable,a T,b T) => bool[src]
lteq -- feature that compares two values using the lteq relation
defined in their type
max(T:property.orderable,a T,b T) => T[src]
maximum of two values
memoize(MM:container.Mutable_Map T R,T:property.equatable,R:Any,f Unary R T) => Unary R T[src]
memoize `f`.
wraps f so that f will only be called once for every unique input.

The term "memoization" was coined by Donald Michie in 1968 and
is derived from the Latin word "memorandum" ("to be remembered"),
usually truncated as "memo" in American English, and thus carries
the meaning of "turning a function into something to be remembered".
https://en.wikipedia.org/wiki/Memoization

example:

min(T:property.orderable,a T,b T) => T[src]
minimum of two values
0.099dev (GIT hash e2d5298d8107bb5fe79600fdb06a49bc75756344)
last changed: 2026-11-23